package com.atguigu.userprofile.dao;

import com.atguigu.userprofile.MysqlUtil.MysqlUtil;
import com.atguigu.userprofile.bean.Taginfo;


import java.lang.reflect.InvocationTargetException;

import java.sql.SQLException;
import java.util.List;


public class TaginfoDao {
    public static void main(String[] args) throws SQLException, NoSuchFieldException, ClassNotFoundException, InvocationTargetException, InstantiationException, IllegalAccessException {
        List<Taginfo> taginfos = selectTagInfosByTaskWithStatusEnable();

        System.out.println(taginfos);
    }

    public static List<Taginfo> selectTagInfosByTaskWithStatusEnable(){
        String querysql=  "SELECT \n" +
                " ti.id ,ti.tag_code , ti.tag_name , ti.tag_level , ti.parent_tag_id , ti.tag_type , ti.tag_value_type , ti.tag_task_id , ti.tag_comment , ti.update_time , ti.create_time \n" +
                "FROM \n" +
                "tag_info ti JOIN task_info tk \n" +
                "ON ti.tag_task_id = tk.id \n" +
                "WHERE tk.task_status = '1' " ;

        List<Taginfo> selectlist = MysqlUtil.selectlist(querysql, Taginfo.class, true);
        return selectlist;
    }

    public static Taginfo selectTagInfoByTaskId(String taskId) throws SQLException, NoSuchFieldException, ClassNotFoundException, InvocationTargetException, InstantiationException, IllegalAccessException {

        String querysql="SELECT id,tag_code,tag_name,parent_tag_id,tag_level,tag_type,tag_value_type,tag_task_id,tag_comment,update_time,create_time FROM tag_info WHERE tag_task_id="+taskId;

        Taginfo selectone = MysqlUtil.selectone(querysql, Taginfo.class, true);

        return selectone;
    }


}
